class Solution {
    public String longestCommonPrefix(String[] strs) {
        String m = strs[0];
        for (int i = 1; i < strs.length; i++) {
            m = same(m, strs[i]);
        }
        return m;
    }
    public String same(String s1, String s2) {
        int i = 0;
        String m = "";
        while (i < s1.length() && i < s2.length()) {
            if (s1.charAt(i) != s2.charAt(i)) {
                break;
            }
            m = s1.substring(0, i + 1);
            i++;
        }
        return m;
    }
}